import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class TestDML2 {
	public static void main(String[] args) {
		
		if(args.length != 3) {
			System.out.println("输入过少，请重新输入");
		}
		
		int deptno = 0;
		try {
			deptno = Integer.parseInt(args[0]);
		} catch(NumberFormatException e) {
			System.out.println("字符格式错误");
			System.exit(-1);
		}
		
		String dname = args[1];
		String loc = args[2];
		
		Statement sta = null;
		Connection conn = null;
		try{
			Class.forName("oracle.jdbc.driver.OracleDriver");
			conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:lovemanai", "scott", "tiger");
			sta = conn.createStatement();
			String sql = "insert into dept2 values (" + deptno + ", '" + dname + "', '" + loc + "')" ;
System.out.println(sql);
			sta.executeUpdate(sql);
		} catch(ClassNotFoundException e) {
			System.out.println("未找到相应驱动");
		} catch(SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				if(sta != null) {
					sta.close();
					sta = null;
				}
				if(conn != null) {
					conn.close();
					conn = null;
				}
			} catch(SQLException e) {
				e.printStackTrace();
			}
			
		}
		
		
	}
}
